package top.datacluster.basic.algorithm.leetcode.heap;

import java.util.Comparator;
import java.util.PriorityQueue;

public class LeetCode1046 {

    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0;i < stones.length; i++){
            queue.offer(stones[i]);
        }
        while (!queue.isEmpty() && queue.size() > 1){
            int first = queue.poll();
            int second = queue.poll();
            queue.offer(first - second);
        }
        return queue.poll();
    }

    public static void main(String[] args) {
        int[] test = new int[]{2,7,4,1,8,1};
        System.out.println(new LeetCode1046().lastStoneWeight(test));
    }
}
